﻿(function(){

var now = { row:1, col:1 }, last = { row:0, col:0};
const towards = { up:1, right:2, down:3, left:4};
var isAnimating = false;

s=window.innerHeight/500;
ss=250*(1-s);

$('.wrap').css('-webkit-transform','scale('+s+','+s+') translate(0px,-'+ss+'px)');

document.addEventListener('touchmove',function(event){
	event.preventDefault(); },false);

$(document).swipeUp(function(){
	if (isAnimating) return;
	last.row = now.row;
	last.col = now.col;
	if (last.row != 8) { now.row = last.row+1; now.col = 1; pageMove(towards.up);}	
})

$(document).swipeDown(function(){
	if (isAnimating) return;
	last.row = now.row;
	last.col = now.col;
	if (last.row!=1) { now.row = last.row-1; now.col = 1; pageMove(towards.down);}	
})

$(document).swipeLeft(function(){
	if (isAnimating) return;
		last.row = now.row;
		last.col = now.col;
	if (last.row>1 && last.row<8&&last.col!=4)
	   { now.col = last.col+1;; pageMove(towards.left);}	   
	
})

$(document).swipeRight(function(){
	if (isAnimating) return;
		last.row = now.row;
		last.col = now.col;
	if (last.row>1 && last.row<8&&now.col!=1)
	   { now.col = last.col-1; pageMove(towards.right);}
})
$(function(){	
	$("#plan1").click(function(){
        if(sp1.className=='active'){
            sp1.className='';
            buy="";
            num.innerHTML='369';
        }else{
            sp1.className='active';
            buy="http://www.baidu.com";//请更改至需要的连接
            num.innerHTML='119';
        }
        sp2.className='';
        sp3.className='';
        sp4.className='';
    },false);
	$("#plan2").click(function(){
        if(sp2.className=='active'){
            sp2.className='';
            buy="";
            num.innerHTML='369';
        }else{
            sp2.className='active';
            buy="http://www.baidu.com";//请更改至需要的连接
            num.innerHTML='219';
        }
        sp1.className='';
        sp3.className='';
        sp4.className='';
    },false);
	$("#plan3").click(function(){
        if(sp3.className=='active'){
            sp3.className='';
            buy="";
            num.innerHTML='369';
        }else{
            sp3.className='active';
            buy="http://www.baidu.com";//请更改至需要的连接
            num.innerHTML='319';
        }
        sp1.className='';
        sp2.className='';
        sp4.className='';
    },false);
	$("#plan4").click(function(){
        if(sp4.className=='active'){
            sp4.className='';
            buy="";
            num.innerHTML='469';
        }else{
            sp4.className='active';
            buy="http://www.baidu.com";//请更改至需要的连接
            num.innerHTML='419';
        }
        sp1.className='';
        sp2.className='';
        sp3.className='';
    },false);
	
		});
		

jQuery.fn.center = function(loaded) {
    var obj = this;
    body_width = parseInt($(window).width());
    body_height = parseInt($(window).height());
    block_width = parseInt(obj.width());
    block_height = parseInt(obj.height());
    
    left_position = parseInt((body_width/2) - (block_width/2)  + $(window).scrollLeft());
    if (body_width<block_width) { left_position = 0 + $(window).scrollLeft(); };
    
    top_position = parseInt((body_height/2) - (block_height/2) + $(window).scrollTop());
    if (body_height<block_height) { top_position = 0 + $(window).scrollTop(); };
    
    if(!loaded) {
        
        obj.css({'position': 'absolute'});
        obj.css({ 'top': top_position, 'left': left_position });
        $(window).bind('resize', function() { 
            obj.center(!loaded);
        });
        $(window).bind('scroll', function() { 
            obj.center(!loaded);
        });
        
    } else {
        obj.stop();
        obj.css({'position': 'absolute'});
        obj.animate({ 'top': top_position }, 200, 'linear');
    }
}
		
		
//隐藏微信中网页底部导航栏
function pageMove(tw){
	var lastPage = ".page-"+last.row+"-"+last.col,
		nowPage = ".page-"+now.row+"-"+now.col;
	
	switch(tw) {
		case towards.up:
			outClass = 'pt-page-moveToTop';
			inClass = 'pt-page-moveFromBottom';
			break;
		case towards.right:
			outClass = 'pt-page-moveToRight';
			inClass = 'pt-page-moveFromLeft';
			break;
		case towards.down:
			outClass = 'pt-page-moveToBottom';
			inClass = 'pt-page-moveFromTop';
			break;
		case towards.left:
			outClass = 'pt-page-moveToLeft';
			inClass = 'pt-page-moveFromRight';
			break;
	}
	isAnimating = true;
	$(nowPage).removeClass("hide");
	
	$(lastPage).addClass(outClass);
	$(nowPage).addClass(inClass);
	
	setTimeout(function(){
		$(lastPage).removeClass('page-current');
		$(lastPage).removeClass(outClass);
		$(lastPage).addClass("hide");
		$(lastPage).find("img").addClass("hide");
		
		$(nowPage).addClass('page-current');
		$(nowPage).removeClass(inClass);
		$(nowPage).find("img").removeClass("hide");
		
		isAnimating = false;
	},600);
}

})();